﻿using App.IRepository;
using App.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace App.Repository
{
    public class UserInfoRepository : BaseRepository<UserInfo>, IUserInfoRepository
    {
        public async override Task<UserInfo> FindAsync(string id)
        {
            return await base.Context.Queryable<UserInfo>()
               .Includes(a => a.Role)
               .InSingleAsync(id);
        }
        public override async Task<List<UserInfo>> QueryAsync()
        {
            return await base.Context.Queryable<UserInfo>()
                .Mapper(c => c.Role, c => c.RoleId, c => c.Role.Id)
                .ToListAsync();
        }
        public async override Task<List<UserInfo>> QueryAsync(Expression<Func<UserInfo, bool>> func)
        {
            return await base.Context.Queryable<UserInfo>()
                .Where(func)
                .Mapper(c => c.Role, c => c.RoleId, c => c.Role.Id)
                 .ToListAsync();
        }
        public async override Task<List<UserInfo>> QueryAsync(int pageIndex, int pageSize, RefAsync<int> total)
        {
            return await base.Context.Queryable<UserInfo>()
                .Mapper(c => c.Role, c => c.RoleId, c => c.Role.Id)
                .ToPageListAsync(pageIndex, pageSize, total);

        }

        public async override Task<List<UserInfo>> QueryAsync(Expression<Func<UserInfo, bool>> func, int pageindex, int pageSize, RefAsync<int> total)
        {
            return await base.Context.Queryable<UserInfo>()
                .Where(func)
                .Mapper(c => c.Role, c => c.RoleId, c => c.Role.Id)
                .ToPageListAsync(pageindex, pageSize, total);
        }
        public UserInfoRepository(ISqlSugarClient context) : base(context)
        {
        }
    }
}
